package com.panda.cn.config.aspect;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panda.cn.component.SpringBeanUtil;
import com.panda.cn.entity.SysOperLogEntity;
import com.panda.cn.mapper.SysOperLogMapper;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OperLogClean {
    
    private final SysOperLogMapper sysOperLogMapper = SpringBeanUtil.getBean(SysOperLogMapper.class);
    
    /**
     * 清除日志 只保留5天
     */
    public void cleanLog(){
        log.info(">>> 清除日志");
        DateTime dateTime = DateUtil.offsetDay(DateUtil.date(), -5);
        LambdaQueryWrapper<SysOperLogEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.le(SysOperLogEntity::getCreateTime, DateUtil.format(dateTime, "yyyy-MM-dd HH:mm:ss"));
        sysOperLogMapper.delete(queryWrapper);
    }
    
    
}
